<template>
	<view class="search">
    <u-navbar  :safeAreaInsetTop="true" bgColor="transparent">
     	<view class="hreder" slot="left">
     		<view class="skip" @click="hopbtn">跳过</view>
     	</view>
    </u-navbar>
		<u-swiper :list="advertlist" imgMode="scaleToFill" :height="heigth" interval="2000"></u-swiper>
	</view>
</template>

<script>
	import {advert} from '@/api/protocol.js'
	export default{
		data(){
			return{
			   advertlist:[],
			   heigth:null,
			   timerid:'',
			   num:0
			}
		},
		methods:{
			async advertapi() {
				const res = await advert(2)
				res.data.forEach(el => this.advertlist.push(el.image))
				this.num = this.advertlist.length
			},
			hopbtn(){
				clearInterval(this.timerid)
				uni.switchTab({
					url:'/pages/index/index'
				})
			}
		},
		async mounted(){
			await this.advertapi()
			this.timerid = setTimeout(()=>{
				uni.switchTab({
					url:'/pages/index/index'
				})
			},this.num*2000);
		},
		onLoad() {
			uni.getSystemInfo({
				success:res=>{
					this.heigth = res.windowHeight
				}
			})
		}
	}
</script>

<style scoped>
	.search{
		position: relative;
		width: 100%;
		height: 100vh;
	}
	.skip{
		padding: 10rpx 40rpx;
		border-radius: 50rpx;
		color: #fff;
		font-size: 30rpx;
		background-color: rgba(0, 0, 0, 0.4);
	}
</style>